const {collectionsModel} =require('../models/collectionsModel');
// 获取收藏题目
async function getCollections(req, res, next) {
    const data=req.query;
    const result=await collectionsModel.find(data).populate('questions_id');
    console.log(result);
    if(result.length>0){
       res.send({
        code:200,
        message:'数据获取成功',
        result
       })
    }else{
        res.send({
            code:500,
            message:"数据获取失败",
            result
        })
    }
  }
//   添加到收藏
async function createCollections(req,res,next){
    const data=req.body;
    const result=await collectionsModel.create(data);
    if(result!=null){
        res.send({
            code:200,
            message:'添加成功',
            
        })
    }else(
        res.send({
            code:500,
            message:'添加失败'
        })
    )
}
// 删除收藏
async function deleteCollections(req,res,next){
    const data=req.body;
    const result= await collectionsModel.deleteOne(data);
    if(result.deletedCount!=0){
        res.send({
            code:200,
            message:'删除成功'
        })
    }else{
        res.send({
            code:500,
            message:'删除失败'
        })
    }
}
  module.exports={
    getCollections,createCollections,deleteCollections
}